<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>新闻信息</title>
    <link href="../../style/css/back/style.css" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        .userType {
            border: 2px solid #3c95c8;
            border-radius: 2px;
        }
    </style>
    <script src="../../style/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        $(function () {
            $.get("../../news/getNewsList", function (res) {
                if (res.code === 500) {
                    alert(res.msg)
                } else if (res.code === 202) {
                    alert("登录失效")
                } else {
                    var str = "";
                    for (let i = 0; i < res.data.length; i++) {
                        str += "<tr align='center'>";
                        str += "<td>" + (i + 1) + "</td>";
                        str += "<td>" + res.data[i].title + "</td>";
                        /*新闻类型*/
                        str += "<td>" + res.data[i].name + "</td>";
                        str += "<td>" + (new Date(res.data[i].publishTime)).toLocaleString() + "</td>";
                        var imgUrl = "http://127.0.0.1:8080/tomorrowNewsFiles/news/" + res.data[i].coverPicture
                        str += "<td><img src='" + imgUrl + "' width='30px' height='30px'></td>"
                        str += "<td>" + res.data[i].clickNum + "</td>";
                        str += "<td>" + res.data[i].likeNum + "</td>";
                        if (res.data[i].state === 0) {
                            str += "<td>草稿</td>";
                        } else if (res.data[i].state === 1) {
                            str += "<td>审核</td>";
                        } else if (res.data[i].state === 2) {
                            str += "<td>正常</td>";
                        } else {
                            str += "<td>下架</td>";
                        }
                        str += "<td>" + res.data[i].operatorAccount + "</td>";
                        str += "<td>" + (new Date(res.data[i].operateTime)).toLocaleString() + "</td>";
                        str += "<td><a onclick='deleteNews(" + res.data[i].id + ")' href='javaScript:void(0)'>删除</a> \t\t\t\t " +
                            "<a onclick='updateNews(" + res.data[i].id + ")' href='javaScript:void(0)'>修改</a>"
                    }
                    $("#newsTable").append(str)
                }
            })

        })

        function deleteNews(newsId) {
            if (confirm("确认删除")) {
                $.get("../../news/deleteNews", {id: newsId}, function (res) {
                    if (res.code === 500) {
                        alert(res.msg)
                    } else if (res.code === 202) {
                        alert("登录失效")
                    } else {
                        location.reload();
                    }
                })
            }
        }

        function updateNews(newsId) {
            location.assign("update.html?newsId="+newsId)
        }

    </script>
</head>

<body>
<div class="rightinfo">
    <!-- 顶部按钮 -->
    <div class="tools">
        <ul class="toolbar">
            <!--增加链接-->
            <a href="add.html">
                <li class="click">
                    <span><img src="../../style/img/back/t01.png"/></span>
                    添加
                </li>
            </a>
            新闻类型 <select id="userType" class="userType" onchange="filter()"></select>
            <a href="statistics.html">
                <li class="click">
                    <span><img src="../../style/img/back/t01.png"/></span>
                    统计
                </li>
            </a>


        </ul>
    </div>
    <!--数据列表 -->
    <table class="tablelist" id="newsTable">
        <tr>
            <th>序号<i class="sort"><img src="../../style/img/back/px.gif"/></i></th>
            <th>标题</th>
            <th>新闻类型</th>
            <th>发布时间</th>
            <th>封面图</th>
            <th>点击量</th>
            <th>点赞量</th>
            <th>状态</th>
            <th>操作人</th>
            <th>操作时间</th>
            <th>操作</th>
        </tr>
    </table>
</div>
</body>
</html>
